import java.util.ArrayList;
import java.util.Arrays;

public class Einstein {
    public static void main(String[] args) {
        long aaa = 0;
        House red = new House(Color.RED.toString());
        House blue = new House(Color.BLUE.toString());
        House white = new House(Color.WHITE.toString());
        House green = new House(Color.GREEN.toString());
        House yellow = new House(Color.YELLOW.toString());
        ArrayList<House> houses = new ArrayList<>();
        houses.addAll(Arrays.asList(red, blue, white, green, yellow));

        ArrayList<String> colors = new ArrayList<>();
        for (Color attr : Color.values()
        ) {
            colors.add(attr.toString());
        }
        ArrayList<ArrayList<String>> twoDimenColors = Pertutation.pert(colors);


        ArrayList<String> pets = new ArrayList<>();
        for (Pet attr : Pet.values()
        ) {
            pets.add(attr.toString());
        }
        ArrayList<ArrayList<String>> twoDimenPets = Pertutation.pert(pets);

        ArrayList<String> cigarettes = new ArrayList<>();
        for (Cigarette attr : Cigarette.values()
        ) {
            cigarettes.add(attr.toString());
        }
        ArrayList<ArrayList<String>> twoDimenCigarettes = Pertutation.pert(cigarettes);


        ArrayList<String> nationalities = new ArrayList<>();
        for (Nationality attr : Nationality.values()
        ) {
            nationalities.add(attr.toString());
        }
        ArrayList<ArrayList<String>> twoDimenNationalities = Pertutation.pert(nationalities);


        ArrayList<String> drinks = new ArrayList<>();
        for (Drink attr : Drink.values()
        ) {
            drinks.add(attr.toString());
        }
        ArrayList<ArrayList<String>> twoDimenDrinks = Pertutation.pert(drinks);
        for (ArrayList<String> oneDimenColors : twoDimenColors
        ) {
            for (ArrayList<String> oneDimenPets : twoDimenPets
            ) {
                for (ArrayList<String> oneDimenCigarettes : twoDimenCigarettes
                ) {
                    for (ArrayList<String> oneDimenDrinks : twoDimenDrinks
                    ) {
                        for (ArrayList<String> oneDimenNationalities : twoDimenNationalities
                        ) {
                            int i = 0;
                            for (String nationality : oneDimenNationalities
                            ) {
                                houses.get(i++).nationality = nationality;
                            }
                            i = 0;
                            for (String pet : oneDimenPets
                            ) {
                                houses.get(i++).pet = pet;

                            }
                            i = 0;
                            for (String color : oneDimenColors
                            ) {
                                houses.get(i++).color = color;

                            }
                            i = 0;
                            for (String drink : oneDimenDrinks
                            ) {

                                houses.get(i++).drink = drink;

                            }
                            i = 0;
                            for (String cigarette : oneDimenCigarettes
                            ) {

                                houses.get(i++).cigarette = cigarette;
                            }
                            if (judge(houses)) {
                                System.out.println(getNationalityByPet(houses));
                                return;
                            }

                        }
                    }
                }
            }
        }

    }

    private static boolean judge(ArrayList<House> houses) {
        boolean[] flag = new boolean[15];
        Arrays.fill(flag, false);
        for (House house : houses
        ) {
            if (house.nationality.equals(Nationality.English.toString()) && house.color.equals(Color.RED.toString())) {
                flag[0] = true;
            }
        }

        for (House house : houses
        ) {
            if (house.nationality.equals(Nationality.Swede.toString()) && house.pet.equals(Pet.DOG.toString())) {
                flag[1] = true;
            }
        }
        for (House house : houses
        ) {
            if (house.nationality.equals(Nationality.Danish.toString()) && house.drink.equals(Drink.TEA.toString())) {
                flag[2] = true;
            }
        }
        for (House house : houses
        ) {
            if (house.color.equals(Color.GREEN.toString())) {
                if (houses.get(houses.indexOf(house) + 1).color.equals(Color.WHITE.toString())) {
                    flag[3] = true;
                }
                if (house.drink.equals(Drink.CAFE.toString())) {
                    flag[4] = true;
                }
            }
        }
        for (House house : houses
        ) {
            if (house.cigarette.equals(Cigarette.PALLMALL.toString()) && house.pet.equals(Pet.BIRD.toString())) {
                flag[5] = true;
            }
        }
        for (House house : houses
        ) {
            if (house.color.equals(Color.YELLOW.toString()) && house.cigarette.equals(Cigarette.DUNHILL.toString())) {
                flag[6] = true;
            }
        }

        if (houses.get(2).drink.equals(Drink.MILK.toString())) {
            flag[7] = true;
        }
        if (houses.get(0).nationality.equals(Nationality.Norwegian.toString())) {
            flag[8] = true;
        }
        for (House house : houses
        ) {
            if (house.cigarette.equals(Cigarette.BLENDS.toString())) {
                int cIndex = houses.indexOf(house);
                for (House house2 : houses
                ) {
                    if (house2.pet.equals(Pet.Cat.toString())) {
                        if (houses.indexOf(house2) == cIndex + 1 || houses.indexOf(house2) == cIndex - 1) {
                            flag[9] = true;
                        }
                    }
                }
            }
        }
        for (House house : houses
        ) {
            if (house.pet.equals(Pet.HORSE.toString())) {
                int cIndex = houses.indexOf(house);
                for (House house2 : houses
                ) {
                    if (house2.cigarette.equals(Cigarette.DUNHILL.toString())) {
                        if (houses.indexOf(house2) == cIndex + 1 || houses.indexOf(house2) == cIndex - 1) {
                            flag[10] = true;
                        }
                    }
                }
            }
        }
        for (House house : houses
        ) {
            if (house.cigarette.equals(Cigarette.BLUEMASTER.toString()) && house.drink.equals(Drink.BEER.toString())) {
                flag[11] = true;
            }
        }
        for (House house : houses
        ) {
            if (house.nationality.equals(Nationality.German.toString()) && house.cigarette.equals(Cigarette.PRINCE.toString())) {
                flag[12] = true;
            }
        }
        for (House house : houses
        ) {
            if (house.nationality.equals(Nationality.Norwegian.toString())) {
                int cIndex = houses.indexOf(house);
                for (House house2 : houses
                ) {
                    if (house2.color.equals(Color.BLUE.toString())) {
                        if (houses.indexOf(house2) == cIndex + 1 || houses.indexOf(house2) == cIndex - 1) {
                            flag[13] = true;
                        }
                    }
                }
            }
        }
        for (House house : houses
        ) {
            if (house.cigarette.equals(Cigarette.BLENDS.toString())) {
                int cIndex = houses.indexOf(house);
                for (House house2 : houses
                ) {
                    if (house2.drink.equals(Drink.WATER.toString())) {
                        if (houses.indexOf(house2) == cIndex + 1 || houses.indexOf(house2) == cIndex - 1) {
                            flag[14] = true;
                        }
                    }
                }
            }
        }

        for (boolean i : flag
        ) {
            if (!i) return false;
        }
        return true;
    }

    private static String getNationalityByPet(ArrayList<House> houses) {
        for (House house : houses
        ) {
            if (house.pet.equals(Pet.FISH.toString())) {
                return house.nationality;
            }
        }
        return null;
    }
}

enum Color {
    YELLOW("yellow"), BLUE("blue"), RED("red"), GREEN("green"), WHITE("white");
    private final String color;

    private Color(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return this.color;
    }
}

enum Nationality {
    Norwegian("Norwegian"), Danish("Danish"), English("English"), German("German"), Swede("Swede");
    private final String nationality;

    private Nationality(String nationality) {
        this.nationality = nationality;
    }

    @Override
    public String toString() {
        return this.nationality;
    }
}

enum Drink {
    WATER("water"), TEA("tea"), MILK("milk"), CAFE("cafe"), BEER("beer");
    private final String drink;

    private Drink(String drink) {
        this.drink = drink;
    }

    @Override
    public String toString() {
        return this.drink;
    }
}

enum Cigarette {
    DUNHILL("DUNHILL"), BLENDS("BLENDS"), PALLMALL("PALLMALL"), BLUEMASTER("BLUEMASTER"), PRINCE("PRINCE"),
    ;
    private final String cigarette;

    Cigarette(String cigarette) {
        this.cigarette = cigarette;
    }

    @Override
    public String toString() {
        return this.cigarette;
    }
}

enum Pet {
    Cat("cat"), HORSE("horse"), BIRD("bird"), FISH("fish"), DOG("dog");
    private final String pet;

    private Pet(String pet) {
        this.pet = pet;
    }

    @Override
    public String toString() {
        return this.pet;
    }
}

